﻿/* **********************************************************************************
 *
 * Copyright (c) WickedFlame Projects. All rights reserved.
 *
 * This source code is subject to terms and conditions of the Microsoft Reciprocal License
 * for WickedFlame. A copy of the license can be found in the License.html file
 * at the root of this distribution. 
 * By using this source code in any fashion, you are agreeing to be bound by
 * the terms of the Microsoft Reciprocal License for WickedFlame.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * **********************************************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Gencode.Controls.NavigationPane
{
    [ToolboxBitmap(typeof(ResFinder), "Gencode.Controls.NavigationPane.bmp")]
    [ToolboxItem(true)]
	public partial class NavigationPane : UserControl
	{
		public NavigationPane()
		{
			InitializeComponent();
            nodes = new NavigationPaneCollection(this);
		}

        internal void ResetSplitterdistance()
        {
            int h = 0;
			int margin = 0;
			foreach (NavigationPaneItem item in Nodes)
			{
				h += item.Button.Height;
				margin = (item.Button.Margin.Top + item.Button.Margin.Bottom);
			}

            NodeContainer.IsSplitterFixed = false;
			if (h > 0)
				NodeContainer.SplitterDistance = h + margin;
            NodeContainer.IsSplitterFixed = true;
        }

        NavigationPaneCollection nodes;
        public NavigationPaneCollection Nodes
        {
            get
            {
                if (nodes == null)
                    nodes = new NavigationPaneCollection(this);
                return nodes;
            }
            set
            {
                nodes = value;
            }
        }

        internal SplitContainer NodeContainer
        {
            get
            {
                return buttonContainer;
            }
        }

        Control currentControl;
        internal Control CurrentControl
        {
            get
            {
                return currentControl;
            }
            set
            {
                currentControl = value;
            }
        }

        internal void navigationButton_Click(object sender, NavigationButtonClickEventArgs e)
        {
            if (currentControl != null)
            {
                currentControl.Visible = false;
                buttonContainer.Panel1.Controls.Remove(currentControl);
            }

            currentControl = e.NextControl;
            currentControl.Visible = true;
            buttonContainer.Panel2.Controls.Add(currentControl);
        }
	}
}
